<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('篮球')" />
	<style type="text/css">
		#menu{
			width: 0; /*设置为0 隐藏自定义菜单*/
			height: 60px;
			overflow: hidden; /*隐藏溢出的元素*/
			box-shadow: 0 1px 1px #888,1px 0 1px #ccc;
			position: absolute; /*自定义菜单相对与body元素进行定位*/
			z-index: 999;
			background-color: #ffffff;
		}
		.menu{
			width: 130px;
			height: 25px;
			line-height: 25px;
			padding: 0 10px;
			background-color: #ffffff;
       		color: #000000;
		}
		.menu:hover {
       		background-color: #66FFFF;
       		color: #ffffff;
       		cursor:pointer;
       	}
	</style>
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="post-form">
					<div class="select-list">
						<ul>
							<li>
								投注金额：<input type="text"  value="10000" id="tzje"/>
							</li>
							<li>
								竞彩返点：<input type="text" value="0.095"  id="jcfd"/>
							</li>
							<li>
								HG返点：<input type="text" value="0.023"  id="hgfd"/>
							</li>
							<li>
								收益率大于：<input type="text"  id="syl"/>%
							</li>
							<li>
								竞彩返还率大于：<input type="text"  id="fhl"/>%
							</li>
							<li>
								收益大于：<input type="text" id="sy"/>
							</li>
							<li>
								利润达标提醒设置：<input type="text" value="300" id="lrdb"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm"><i class="fa fa-cog"></i>&nbsp;设置</a>
							    <a class="btn btn-warning btn-rounded btn-sm" id="resetTime"><i class="fa fa-clock-o"></i>&nbsp;设置刷新时间</a>
								<span style="color: red;" id="timeText">10s</span><span>秒刷新</span>
								<input type="hidden" value="10" id="time"/>
							</li>
						</ul>
					</div>
				</form>
			</div>
	        <div class="col-sm-12 select-table table-striped" id="continer">
	        	
			</div>
			<div class="col-sm-12 select-table table-striped" id="continer_1">
	        	
			</div>
			<div class="col-sm-12 select-table table-striped" id="continer_2">
	        	
			</div>
		</div>
		<div id="menu">
			<div class="menu" onclick="addFisrt()">添加第一行</div>
			<div class="menu" onclick="addSecond()">添加第二行</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		function cellStylesales(value, row, index) {
			return {css:{background:'#FF9933'}};
		};
		var rowData, menuVisible;
		var prefix = ctx + "system/manager";
		function openStTable(t){
			var majorRow = {};
            majorRow.title = t.HomeField + " VS " + t.OpponentField,
            majorRow.betAmount = $('#tzje').val(),
            majorRow.jc = t.LotteryPlateOdds.split("：")[1],
            majorRow.hg = t.PeripheryPlateOdds.split("：")[1],
            majorRow.betMoneyFlat = t.BetMoneyFlat,
            majorRow.betMoneyPeriphery = t.BetMoneyPeriphery,
            majorRow.Income1 = t.Income1,
            majorRow.TotalExpense = t.TotalExpense,
            majorRow.profit = t.Income1 + t.BetMoneyJingCai * $('#jcfd').val() - t.TotalExpense
            localStorage.setItem("dggpDetail", JSON.stringify(majorRow));
            $.modal.open(majorRow.title, prefix+'/lq/detail', 800, 300, function(){
            	
            });
		};
		var options1 = {
				showRefresh: false,
	            showColumns: false,
				showToggle: false,
				showSearch: false,
				onClickCell: function(field, value, row, $element){
					7 === field && openStTable(row);
				},
		        columns: [
					{
						field: 'Type',
						title: '类型'
					},
					{
						field: 'LotteryPlateOdds',
						title: '竞彩',
						cellStyle:cellStylesales,
						formatter: function(value, row, index) {
			                return '<span style="color:blue;">'+value+'</span>';
			            }
					},
					{
						field: 'PeripheryPlateOdds',
						title: '外围',
						formatter: function(value, row, index) {
							if(value.indexOf('J')>-1) return '<span style="color:blue;">'+value+'</span>';
			                return '<span style="color:#FF0066;">'+value+'</span>';
			            }
					},
					{
						field: 'BetMoneyWinLose',
						title: '竞猜下注额',
						formatter: function(value, row, index) {
			                return '<span style="color:#993300;">'+value+'</span>';
			            }
					},
					{
						field: 'BetMoneyPeriphery',
						title: '外围下注额',
						formatter: function(value, row, index) {
			                return '<span style="color:#993300;">'+value+'</span>';
			            }
					},
					{
						field: 'ProfitLotteryPercent',
						title: '收益',
						formatter: function(value, row, index) {
							var ProfitLotteryPercent = ((row.Income1 + row.BetMoneyJingCai * $('#jcfd').val() - row.TotalExpense) / row.BetMoneyJingCai * 100).toFixed(2) + "%";
							if(ProfitLotteryPercent>0) return '<span style="color:red;">'+ProfitLotteryPercent+'%</span>';
			                return '<span style="color:#00CC00;">'+ProfitLotteryPercent+'%</span>';
			                return 
			            }
					},
					{
						filed: 'RewordReturn',
						title: '返回',
						formatter: function(value, row, index) {
							var RewordReturn = (100 * row.RewordReturn).toFixed(2) + "%";
			                return '<span style="color:#00CC00;">'+RewordReturn+'</span>';
			            }
					},
					{
						filed: 'Profit',
						title: '利润',
						formatter: function(value, row, index) {
							var jcReturn = $('#jcfd').val();
							var profit = (row.Income1 + row.BetMoneyJingCai * jcReturn - row.TotalExpense).toFixed(2);
							if(profit>0) return '<span style="color:red;">'+profit+'</span>';
			                return '<span style="color:#00CC00;">'+profit+'</span>';
			            }
					}
			    ]
		};
		var options2 = {
				showRefresh: false,
	            showColumns: false,
				showToggle: false,
				showSearch: false,
		        columns: []
		};
		var times = $('#time').val();
		if(localStorage.getItem("time")) {
			times = localStorage.getItem("time");
			$('#time').val(times);
		}
        var setTimes = function() {
        	setInterval((function() {
        		times =  times-1;
        		if(times < 0) {
        			times = $('#time').val();
        			getData(true)
        		}
                $('#timeText').text(times+"s");
            }), 1e3)
		};
		var renderTable = function(result) {
			if(!result || result<1) return;
			var dateDiff = function(t) {
                var e = new Date
                  , r = new Date(t)
                  , i = (r - e) / 1e3
                  , a = parseInt(i / 86400)
                  , n = parseInt(i / 3600) - 24 * a
                  , o = parseInt(i % 3600 / 60)
                  , l = parseFloat((o / 60).toFixed(1));
                return 24 * a + n + l + "小时后开赛"
            };
			function renderItem(item,index) {
				var html = [];
				html.push('<div class="row">')
				if(index==1) {
					html.push('<h4 class="form-header h4" style="font-weight: bold;font-size: 20px">篮球胜负</h4>');
				}
				html.push('<h4 class="form-header h4">'+index+'.【'+item.SerialNumber+'】'+dateDiff(item.StartTime)+'('+item.StartTime+')'+item.LeagueName + ' => ' + item.HomeField + 'Vs '+ item.OpponentField+'</h4>');
				html.push('<div class="col-sm-7">');
				html.push('	<table id="bootstrap-table1"></table>');
				html.push('</div>');
				html.push('<div class="col-sm-5">');
				html.push('	<table id="bootstrap-table2"></table>');
				html.push('</div>');
				html.push('</div>');
				var html = $(html.join('\r\n'));
				return html;
			}
			var continer = $('#continer');
			continer.empty();
			for(var i=0; i<result.length; i++) {
				var div = renderItem(result[i], i+1);
				var table1 = div.find('#bootstrap-table1');
				var table2 = div.find('#bootstrap-table2');
				continer.append(div);
				options1.data = result[i].EventHedgeProfitsBKWinLose;
				table1.bootstrapTable(options1);
				var EventPlateBKWinLoseDetailInfos = result[i].EventPlateBKWinLoseDetailInfos;
				if(!EventPlateBKWinLoseDetailInfos || EventPlateBKWinLoseDetailInfos.length<1) continue;
				var EventPlateBKWinLoseDetailInfo = EventPlateBKWinLoseDetailInfos[0];
				var cl = [];
				for(var key in EventPlateBKWinLoseDetailInfo) {
					var json = {
							field: key,
							title: EventPlateBKWinLoseDetailInfo[key]
						};
					cl.push(json);
				}
				options2.columns = cl;
				EventPlateBKWinLoseDetailInfos.splice(0,1);
				options2.data = EventPlateBKWinLoseDetailInfos;
				table2.bootstrapTable(options2);
			}
			console.log(result);
		};
		var renderTable1 = function(result) {
			if(!result || result<1) return;
			var dateDiff = function(t) {
                var e = new Date
                  , r = new Date(t)
                  , i = (r - e) / 1e3
                  , a = parseInt(i / 86400)
                  , n = parseInt(i / 3600) - 24 * a
                  , o = parseInt(i % 3600 / 60)
                  , l = parseFloat((o / 60).toFixed(1));
                return 24 * a + n + l + "小时后开赛"
            };
			function renderItem(item,index) {
				var html = [];
				html.push('<div class="row">')
				if(index==1) {
					html.push('<h4 class="form-header h4" style="font-weight: bold;font-size: 20px">篮球让球胜负</h4>');
				}
				html.push('<h4 class="form-header h4">'+index+'.【'+item.SerialNumber+'】'+dateDiff(item.StartTime)+'('+item.StartTime+')'+item.LeagueName + ' => ' + item.HomeField + 'Vs '+ item.OpponentField+'</h4>');
				html.push('<div class="col-sm-7">');
				html.push('	<table id="bootstrap-table1"></table>');
				html.push('</div>');
				html.push('<div class="col-sm-5">');
				html.push('	<table id="bootstrap-table2"></table>');
				html.push('</div>');
				html.push('</div>');
				var html = $(html.join('\r\n'));
				return html;
			}
			var continer = $('#continer_1');
			continer.empty();
			for(var i=0; i<result.length; i++) {
				var div = renderItem(result[i], i+1);
				var table1 = div.find('#bootstrap-table1');
				var table2 = div.find('#bootstrap-table2');
				continer.append(div);
				options1.data = result[i].EventHedgeProfitsBKPointWinLose;
				table1.bootstrapTable(options1);
				var EventPlateBKPointWinLoseDetailInfos = result[i].EventPlateBKPointWinLoseDetailInfos;
				if(!EventPlateBKPointWinLoseDetailInfos || EventPlateBKPointWinLoseDetailInfos.length<1) continue;
				var EventPlateBKPointWinLoseDetailInfo = EventPlateBKPointWinLoseDetailInfos[0];
				var cl = [];
				for(var key in EventPlateBKPointWinLoseDetailInfo) {
					var json = {
							field: key,
							title: EventPlateBKPointWinLoseDetailInfo[key]
						};
					cl.push(json);
				}
				options2.columns = cl;
				EventPlateBKPointWinLoseDetailInfos.splice(0,1);
				options2.data = EventPlateBKPointWinLoseDetailInfos;
				table2.bootstrapTable(options2);
			}
			console.log(result);
		};
		var renderTable2 = function(result) {
			if(!result || result<1) return;
			var dateDiff = function(t) {
                var e = new Date
                  , r = new Date(t)
                  , i = (r - e) / 1e3
                  , a = parseInt(i / 86400)
                  , n = parseInt(i / 3600) - 24 * a
                  , o = parseInt(i % 3600 / 60)
                  , l = parseFloat((o / 60).toFixed(1));
                return 24 * a + n + l + "小时后开赛"
            };
			function renderItem(item,index) {
				var html = [];
				html.push('<div class="row">')
				if(index==1) {
					html.push('<h4 class="form-header h4" style="font-weight: bold;font-size: 20px">篮球大小分</h4>');
				}
				html.push('<h4 class="col-sm-12 form-header h4">'+index+'.【'+item.SerialNumber+'】'+dateDiff(item.StartTime)+'('+item.StartTime+')'+item.LeagueName + ' => ' + item.HomeField + 'Vs '+ item.OpponentField+'</h4>');
				html.push('<div class="col-sm-7">');
				html.push('	<table id="bootstrap-table1"></table>');
				html.push('</div>');
				html.push('<div class="col-sm-5">');
				html.push('	<table id="bootstrap-table2"></table>');
				html.push('</div>');
				html.push('</div>');
				var html = $(html.join('\r\n'));
				return html;
			}
			var continer = $('#continer_2');
			continer.empty();
			for(var i=0; i<result.length; i++) {
				var div = renderItem(result[i], i+1);
				var table1 = div.find('#bootstrap-table1');
				var table2 = div.find('#bootstrap-table2');
				continer.append(div);
				options1.data = result[i].EventHedgeProfitsBKSize;
				table1.bootstrapTable(options1);
				var EventPlateBKSizeDetailInfos = result[i].EventPlateBKSizeDetailInfos;
				if(!EventPlateBKSizeDetailInfos || EventPlateBKSizeDetailInfos.length<1) continue;
				var EventPlateBKSizeDetailInfo = EventPlateBKSizeDetailInfos[0];
				var cl = [];
				for(var key in EventPlateBKSizeDetailInfo) {
					var json = {
							field: key,
							title: EventPlateBKSizeDetailInfo[key]
						};
					if(json.title==='盘口') {
						json.formatter = function(value, row, index) {
			                return '<span style="color:#00CC00;">'+value+'</span>';
			            }
					}
					cl.push(json);
				}
				options2.columns = cl;
				EventPlateBKSizeDetailInfos.splice(0,1);
				options2.data = EventPlateBKSizeDetailInfos;
				table2.bootstrapTable(options2);
			}
		};
        var getData = function(isReset) {
			var baseUrl = "http://83t95.xyz:8090/api/BKWinLose?t="+(new Date).getTime();
			$.operate.get(baseUrl, renderTable, true, isReset);
			baseUrl = "http://83t95.xyz:8090/api/BKPointWinLose?t="+(new Date).getTime();
			$.operate.get(baseUrl, renderTable1, true, isReset);
			baseUrl = "http://83t95.xyz:8090/api/BKSize?t="+(new Date).getTime();
			$.operate.get(baseUrl, renderTable2, true, isReset);
        };		
        
		$(function() {
			getData();
			setTimes();
			$('#resetTime').on('click', function(){
				layer.prompt({title: '输入刷新时间单位(秒)', formType: 0}, function(pass, index){
					if(!pass || pass=='') return $.modal.msgWarning("请填写刷新时间");
					if(parseFloat(pass).toString() == "NaN") return $.modal.msgWarning("请填写正整数");
					$('#time').val(pass);
					localStorage.setItem("time",pass);
					layer.close(index);
				});
			});
		});
	</script>
</body>
</html>